﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Workflows.Components.Entities.Properties;

namespace Workflows.Components.Entities.MasterData
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class FieldDistributionComponent:WorkflowComponentBase
    {
        #region Overrides of WorkflowComponentBase

        private FieldDistributionInstruction _Instruction;
        /// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
        {
            get { return _Instruction; }
            set { _Instruction=(FieldDistributionInstruction)value; }
        }

        private FieldDistributionOutput _Output;
        /// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
        {
            get { return _Output; }
            set { _Output=(FieldDistributionOutput)value; }
        }

        #endregion

        public FieldDistributionComponent():base()
        {
            this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
            this.ComponentCategory = WorkflowComponentCategory.Entity_Relations.ToString();
            this.Description = "Field distribution measure";
            this.ComponentIcon = Resources.wdc_10024;
            this.ComponentImage = Resources.DatabaseSelectColumn48;
            this.ComponentName = "Gini distribution";

            this._Instruction = new FieldDistributionInstruction(
                this.ComponentID, Guid.Empty, string.Empty, string.Empty, string.Empty,
                string.Empty, string.Empty, string.Empty, string.Empty, 10);
            this._Output = new FieldDistributionOutput(Guid.Empty, Guid.Empty, 0);
        }

        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
            this.Instruction.Serialize(ref xDoc, ref xNode);
            return xNode;
        }

        public override WorkflowComponentBase Instantiate(XmlNode xNode)
        {
            FieldDistributionComponent component = (FieldDistributionComponent)base.Instantiate(xNode);
            component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
            return component;
        }
    }
}
